//FileHelper.h
#if !defined(AFX_FILEHELPER_H__54D6ED98_4A20_4953_990F_301B76C6C87E__INCLUDED_)
#define AFX_FILEHELPER_H__54D6ED98_4A20_4953_990F_301B76C6C87E__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define EF_ONLY_FILENAMES    0
#define EF_FULLY_QUALIFIED    1

class CFileHelper
{
public:
	// ctor(s)
	CFileHelper();
	CFileHelper( CWnd* feedbackWindow );
	static CFileHelper * Instance();
	static void DeleteInstance();
	// dtor
	~CFileHelper();

	// - - -
	// Operations

	// Files
	CString GetAppPath();
	BOOL FileExists( const CString& file );
	BOOL FileInformation( const CString& file, BY_HANDLE_FILE_INFORMATION &file_info);
	BOOL CreateFile( const CString& file );
	BOOL CopyFile( const CString& sourceFile, const CString& destDirectory );
	BOOL CopyFile( const CString& sourceFile, const CString& destDirectory, const CString& destFile );
	BOOL RemoveFile( const CString& sourceFile );
	BOOL RenameFile( const CString& sourceFile, const CString& destFile );
	BOOL MoveFile( const CString& sourceFile, const CString& destFile );

	BOOL CopyFiles( const CString& sourceDirectory, const CString& destDirectory );
	BOOL CopyFiles( CStringArray& files, const CString& destDirectory );

	// Directories

	BOOL DirectoryExists( const CString& file );

	BOOL CreateDirectory( const CString& directory );
	BOOL CopyDirectory( const CString& sourceDirectory, const CString& destDirectory );
	BOOL EmptyDirectory( const CString& directory );
	BOOL RemoveDirectory( const CString& directory );

	BOOL CopyDirectories( const CString& sourceDirectory, const CString& destDirectory );
	BOOL EmptyDirectories( const CString& directory );
	BOOL RemoveDirectories( const CString& directory );

	BOOL EnumFilesInDirectoryWithFilter( const CString& filter, const CString& sourceDirectory, CStringArray& files, int mode = EF_ONLY_FILENAMES );
	BOOL EnumAllDirectories( const CString& sourceDirectory, CStringArray& directories );
	BOOL EnumDirectories( const CString& sourceDirectory, CStringArray& directories );
	BOOL EnumFilesInDirectory( const CString& sourceDirectory, CStringArray& files, int mode = EF_ONLY_FILENAMES );
	BOOL EnumAllFiles( const CString& sourceDirectory, CStringArray& files );
	BOOL EnumAllFilesWithFilter( const CString& filter, const CString& sourceDirectory, CStringArray& files );

	// Error handling
	CString GetErrorMessage();

private:
	static CFileHelper * m_pInstance;
	// Error handling
	CString m_errorMessage;

	void    ClearError();
	void    SetInternalErrorMessage();
	void    SetSystemErrorMessage( int error, const CString& elements = _T( "" ) );

	// Helpers

	CWnd*    m_feedbackWindow;
	void    QualifyPath( CString& str );
	void    QualifyFile( CString& str );
	CString GetFileName( const CString& str );
	CString GetDirectoryName( const CString& str );
};
#endif // !defined(AFX_FILEHELPER_H__54D6ED98_4A20_4953_990F_301B76C6C87E__INCLUDED_)
